const { where } = require("sequelize");
const Order = require("../model/orderModel");
class OrderService {
  async createOrder(order) {
    return await Order.create(order);
  }
  async findAllOrder(pageNum, pageSize, status) {
    console.log(`Fetching orders with status: ${status}`);

    const { count, rows } = await Order.findAndCountAll({
      attributes: ["goods_info", "total", "order_code", "status"],
      where: {
        status: String(status), // 确保类型匹配
      },
      offset: (pageNum - 1) * pageSize,
      limit: pageSize * 1,
    });

    console.log(`Fetched ${count} orders, Rows: ${JSON.stringify(rows)}`);

    return {
      pageNum,
      pageSize,
      total: count,
      list: rows,
    };
  }
  async updateOrder(id, status){
    return await Order.update({status}, {where: {id}})
  }
}
module.exports = new OrderService();
